package com.huicoo.forestmanager.widget;

import android.app.AlertDialog;
import android.content.Context;
import android.os.Bundle;

import com.huicoo.forestmanager.R;

import java.lang.ref.WeakReference;

/**
 * Created by Administrator on 2016/4/26.
 */
public class LoadingDialog extends AlertDialog {
    private OnLoadingCancelListener onLoadingCancelListener;

    public LoadingDialog(Context context) {
        super(context, R.style.MyLoadDialog);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.widget_loading_dialog);
        setCanceledOnTouchOutside(false);
        setCancelable(true);

        setOnCancelListener(dialog -> {
            if (onLoadingCancelListener != null) {
                onLoadingCancelListener.cancel();
            }
        });
    }

    public void setOnLoadingCancelListener(WeakReference<OnLoadingCancelListener> onLoadingCancelListenerReference) {
        this.onLoadingCancelListener = onLoadingCancelListenerReference.get();
    }

    public interface OnLoadingCancelListener {
        void cancel();
    }
}
